package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import com.sky.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店铺相关接口")
@RestController("adminShopController")
@RequestMapping("/admin/shop")
public class ShopController {

	public static final String SHOP_STATUS = "SHOP_STATUS";
	@Autowired
	private RedisUtil redisUtil;

	@PutMapping("/{status}")
	@ApiOperation("设置店铺营业状态")
	public Result setStatus(@PathVariable Integer status){
		redisUtil.set(SHOP_STATUS,status);
		log.info("现在将店铺营业状态设置为:{}", StatusConstant.ENABLE.equals(status)?"营业":"打烊");
		return Result.success();
	}

	@GetMapping("/status")
	@ApiOperation("店铺获取店铺营业状态")
	public Result<Integer> getStatus(){
		Integer status = (Integer) redisUtil.get(SHOP_STATUS);
		log.info("店铺获取到店铺的营业状态为：{}",StatusConstant.ENABLE.equals(status) ?"营业":"打烊");
		return Result.success(status);
	}
}
